package com.hc.jdbc.transfer;
import java.sql.Connection;
import java.sql.PreparedStatement;
/**
 * t_bank表数据库操作类
 */
public class BankDao {
    //加钱
    public void add(String account, int money, Connection connection) throws
            Exception {
        String sql = "update t_bank set money=money+? where account=?;";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setObject(1, money);
        statement.setObject(2, account);

        int rows = statement.executeUpdate();
        if (rows > 0) {
            System.out.println("加钱成功");
        } else {
            System.out.println("加钱失败");
        }
    }

    //减钱
    public void sub(String account, int money, Connection connection) throws
            Exception {
        String sql = "update t_bank set money=money-? where account=?;";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setObject(1, money);
        statement.setObject(2, account);
        int i = statement.executeUpdate();
        if (i > 0) {
            System.out.println("减钱成功");
        } else {
            System.out.println("减钱失败");
        }
    }
}